//
//  HWCashViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/2/18.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWReadRecordController.h"
#import "HWReadRecordView.h"

@interface HWReadRecordController ()
@property (nonatomic, strong)HWReadRecordView *readRecordView;
@end

@implementation HWReadRecordController

- (HWReadRecordView *)readRecordView
{
    if (!_readRecordView)
    {
        _readRecordView = [[HWReadRecordView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT)];
        WeakSelf(self)
        _readRecordView.getBackInfoBlock = ^(NSString *page) {
            [weakSelf getHaiPageNum:page pageSizes:@"10"];
        };
    }
    return _readRecordView;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self buryPoint];
    
    [self setTitle:@"阅读记录"];
    [self setDefaultNav];
    
    [self getHaiPageNum:@"1" pageSizes:@"10"];
    
    [self.view addSubview:self.readRecordView];
}


#pragma mark - 阅读记录
- (void)getHaiPageNum:(NSString *)pagenum pageSizes:(NSString *)pagesize
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"pageNum" : pagenum,
                               @"pageSize" : pagesize
                               };
    
    WeakSelf(self)
    [MyInfoManager setReadRecordInfo:prarmers sucess:^(id  _Nonnull acceptData) {
        NSNumber *nub = IFNULL(acceptData[@"hasNextPage"], [NSNumber new]);
        NSArray *arr = [NSArray arrayWithArray:acceptData[@"list"]];
      [weakSelf.readRecordView getReadRecordList:arr isNextPage:nub];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
    
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/readRecord"
                               fromId:nil
                                 toId:@"09e6b130852650ad"];
}

@end
